package sh.wnxy.wn38.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sh.wnxy.wn38.config.AlipayConfig;
import sh.wnxy.wn38.entity.AlipayBean;
import sh.wnxy.wn38.service.PaymentService;

import java.io.IOException;
@CrossOrigin
@RestController
public class PaymetController {
    @Autowired
    private PaymentService paymentService;
    @Autowired
    AlipayConfig alipayConfig;
/*
*  /*商户订单号，必填*/


    @RequestMapping(value = "alipay")
    public String toAlipay(@RequestParam("out_trade_no") String out_trade_no,
                           @RequestParam("subject")String subject,
                           @RequestParam("total_amount")double total_amount,
                           @RequestParam("body")String body) throws IOException {
        AlipayBean alipayBean = new AlipayBean();
        alipayBean.setBody(body);
        alipayBean.setOut_trade_no(out_trade_no);
        alipayBean.setSubject(subject);
        alipayBean.setTotal_amount(total_amount);
        System.out.println(alipayBean.toString());
        String result = paymentService.toAlipay(alipayBean);
        return result;
    }
}